<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改角色</title>
    <!-- 控制页面其他url路径的前缀 -->
    <base href="${pageContext.request.contextPath}/">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="statics/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="statics/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">角色名</label>
        <div class="layui-input-block">
            <input type="hidden" name="roleId" value="${role.roleId}"/>
            <input type="text" name="roleName" lay-verify="required|roleName"
                   lay-reqtext="角色名不能为空" placeholder="请输入角色名" value="${role.roleName}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">角色状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="roleStatus" id="checkid" value="${role.roleStatus}"
                   lay-skin="switch" lay-text="正常|禁用"
                   lay-filter="roleStatus" ${role.roleStatus==1?'checked':'' }>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="statics/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        form.verify({
            roleName: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '角色名不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '角色名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '角色名不能全为数字';
                }
            }
        });


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            //console.log(data.field);
            //console.log($("#checkid").is(':checked'));
            data.field.roleStatus=$("#checkid").is(':checked')?1:0;
            $.ajax({
                type:"post",
                url:"role/doEdit",
                data: data.field,
                dataType:"json",
                success:function(json){
                    if(json.code==200){
                        layer.msg(json.message, {icon: 1, shade: this.shade, scrollbar: false, time: 3000, shadeClose: true});
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        //刷新父页面中的数据表格
                        parent.layui.table.reload('currentTableId',{page: {curr: 1}});
                    }else if(json.code==300){
                        layer.msg(json.message, {icon: 2, shade: this.shade, scrollbar: false, time: 3000, shadeClose: true});
                    }
                }
            });
            return false;
        });

    });
</script>
</body>
</html>
